local zuhequan = fk.CreateSkill{
    name = "rmt__zuhequan",
}
Fk:loadTranslationTable{
    ["rmt__zuhequan"] = "组合拳",
    ["@[rmt__zuhequan]1"] = "组合拳",--redLeft    + blackRight
    ["@[rmt__zuhequan]2"] = "组合拳",--redRight   + blackleft
    ["@[rmt__zuhequan]3"] = "组合拳",--blackLeft  + redRight
    ["@[rmt__zuhequan]4"] = "组合拳",--blackRight + redLeft
    ["#rmt__zuhequan_redLeft"] = "<font color='red'>左</font>",
    ["#rmt__zuhequan_redRight"] = "<font color='red'>右</font>",
    ["#rmt__zuhequan_blackLeft"] = "左",
    ["#rmt__zuhequan_blackRight"] = "右",
    [":rmt__zuhequan"] = "连招技(手牌区一侧的牌+另一侧的牌，区域须不同），令此牌额外结算一次，且造成伤害后，你可以重铸受伤角色与你共计三张牌。",
    ["#rmt__zuhequan_recast-ask"] = "组合拳：你可以重铸你与其共计三张牌",
}

Fk:addQmlMark{
    name = "rmt__zuhequan",
    how_to_show = function(name, value)
        if type(value) == "table" then
            return table.concat(table.map(value,Util.TranslateMapper)," ")
        end
        return " "
    end,
    qml_path = ""
}
Fk:addPoxiMethod{
    name = "rmt__zuhequan_recast",
    card_filter = function(to_select, selected, data)
        return #selected < 3
    end,
    feasible = function(selected)
        return #selected == 3
    end,
    prompt = function ()
        return "#rmt__zuhequan_recast-ask"
    end
}

zuhequan:addEffect(fk.CardUsing, {
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(zuhequan.name) and
        data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[zuhequan.name]  --先随便弄个记录，之后再改
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        data.additionalEffect = (data.additionalEffect or 0) + 1
        data.extra_data.rmt__zuhequan = player.id
    end,
})

zuhequan:addEffect(fk.AfterCardUseDeclared, {
    can_refresh = function (self, event, target, player, data)
        return target == player and player:hasSkill(zuhequan.name, true) and data.extra_data and data.extra_data.yisiquanhuangSideCards
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local mark1 = player:getTableMark("@[rmt__zuhequan]1")
        local mark2 = player:getTableMark("@[rmt__zuhequan]2")
        local mark3 = player:getTableMark("@[rmt__zuhequan]3")
        local mark4 = player:getTableMark("@[rmt__zuhequan]4")
        local change1, change2, change3, change4 = false,false,false,false
        if data.extra_data.yisiquanhuangSideCards.red then
            if table.contains(Card:getIdList(data.card), data.extra_data.yisiquanhuangSideCards.red[1]) then
                change1 = true
                if #mark1 == 0 then
                    table.insert(mark1,"#rmt__zuhequan_redLeft")
                else
                    mark1 = {}
                end
                if #mark4 == 1 then
                    change4 = true
                    table.insert(mark4,"#rmt__zuhequan_redLeft")
                end
            end
            if table.contains(Card:getIdList(data.card), data.extra_data.yisiquanhuangSideCards.red[2]) then
                change2 = true
                if #mark2 == 0 then
                    table.insert(mark2,"#rmt__zuhequan_redRight")
                else
                    mark2 = {}
                end
                if #mark3 == 1 then
                    change3 = true
                    table.insert(mark3,"#rmt__zuhequan_redRight")
                end
            end
        end
        if data.extra_data.yisiquanhuangSideCards.black then
            if table.contains(Card:getIdList(data.card), data.extra_data.yisiquanhuangSideCards.black[1]) then
                change3 = true
                if #mark3 == 0 then
                    table.insert(mark3,"#rmt__zuhequan_blackLeft")
                else
                    mark3 = {}
                end
                if #mark2 == 1 then
                    change2 = true
                    table.insert(mark2,"#rmt__zuhequan_blackLeft")
                end
            end
            if table.contains(Card:getIdList(data.card), data.extra_data.yisiquanhuangSideCards.black[2]) then
                change4 = true
                if #mark4 == 0 then
                    table.insert(mark4,"#rmt__zuhequan_blackRight")
                else
                    mark4 = {}
                end
                if #mark1 == 1 then
                    change1 = true
                    table.insert(mark1,"#rmt__zuhequan_blackRight")
                end
            end
        end
        if change1 == false then mark1 = {} end
        if change2 == false then mark2 = {} end
        if change3 == false then mark3 = {} end
        if change4 == false then mark4 = {} end
        if #mark1 == 2 or #mark2 == 2 or #mark3 == 2 or #mark4 == 2 then
            mark1 = {}
            mark2 = {}
            mark3 = {}
            mark4 = {}
            data.extra_data = data.extra_data or {}
            data.extra_data.combo_skill = data.extra_data.combo_skill or {}
            data.extra_data.combo_skill[zuhequan.name] = true
        end
        if #mark1 > 0 then
            room:setPlayerMark(player,"@[rmt__zuhequan]1",mark1)
        else
            room:setPlayerMark(player,"@[rmt__zuhequan]1",0)
        end
        if #mark2 > 0 then
            room:setPlayerMark(player,"@[rmt__zuhequan]2",mark2)
        else
            room:setPlayerMark(player,"@[rmt__zuhequan]2",0)
        end
        if #mark3 > 0 then
            room:setPlayerMark(player,"@[rmt__zuhequan]3",mark3)
        else
            room:setPlayerMark(player,"@[rmt__zuhequan]3",0)
        end
        if #mark4 > 0 then
            room:setPlayerMark(player,"@[rmt__zuhequan]4",mark4)
        else
            room:setPlayerMark(player,"@[rmt__zuhequan]4",0)
        end
    end,
})

zuhequan:addEffect(fk.Damage, {
    can_refresh = function (self, event, target, player, data)
        local card_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
        if card_event then
            local use = card_event.data
            if use.extra_data and use.extra_data.rmt__zuhequan and use.extra_data.rmt__zuhequan == player.id then
                return not data.to.dead and (#player:getCardIds("he")+ #data.to:getCardIds("he")) >= 3
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local to = data.to
        local player_hands = player:getCardIds("he")
        local target_hands = to:getCardIds("he")
        local extra_data = {}
        local visible_data = {}
        for _, id in ipairs(player_hands) do
        if not player:cardVisible(id) then
            visible_data[tostring(id)] = false
        end
        end
        for _, id in ipairs(target_hands) do
        if not player:cardVisible(id) then
            visible_data[tostring(id)] = false
        end
        end
        if next(visible_data) == nil then visible_data = nil end
        extra_data.visible_data = visible_data
        local cards = room:askToPoxi(player, {
            poxi_type = "rmt__zuhequan_recast",
            data = {
                { player.general, player_hands },
                { to.general, target_hands },
            },
            extra_data = extra_data,
            cancelable = true,
        })
        local mycards=table.filter(cards,function(cid) return table.contains(player_hands,cid) end)
        local othercards=table.filter(cards,function(cid) return table.contains(target_hands,cid) end)
        if #mycards > 0 then room:recastCard(mycards, player, zuhequan.name) end
        if #othercards > 0 then room:recastCard(othercards, to, zuhequan.name) end
    end,
})

return zuhequan